package izzat.fit.training.controller;

import izzat.fit.training.entity.RequestEntity;
import izzat.fit.training.entity.ResponseEntity;
import izzat.fit.training.remote.DBRemote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: TrainingController
 * @Description: 训练控制器
 * @Author: Izzat
 * @Date: 2020-01-16 14:55
 * @Version: v1.0
 */
@RestController
public class TrainingController {

    @Autowired
    DBRemote dbRemote;

    @RequestMapping("test")
    /**
     * @Description: 测试是否正常启动
     * @Param: []
     * @return: java.lang.String
     * @Author: Izzat
     * @Date: 2019/12/31  19:11
     */
    public String test() {
        return "TrainingController";
    }

    @RequestMapping("hello")
    /**
     * @Description: 测试是否成功调用 db-service 服务
     * @Param: []
     * @return: java.lang.String
     * @Author: Izzat
     * @Date: 2019/12/31  19:12
     */
    public String hello() {
        return dbRemote.hello();
    }

    @RequestMapping("allPlan")
    /**
     * @Description: 获取所有动作
     * @Param: []
     * @return: java.lang.String
     * @Author: Izzat
     * @Date: 2019/12/31  19:23
     */
    public ResponseEntity allAction() {
        return dbRemote.allPlan();
    }

    @RequestMapping("findPlanById")
    /**
    * @Description: 按id找训练计划
    * @Param: [id]
    * @return: izzat.fit.training.entity.ResponseEntity
    * @Author: Izzat
    * @Date: 2020/1/16  15:31
    */
    public ResponseEntity findPlanById(@RequestBody RequestEntity request) {
        return dbRemote.findPlanById(request.getId());
    }

    @RequestMapping("findPlanByCreator")
    /** 
    * @Description: 按创建者查找 
    * @Param: [id] 
    * @return: izzat.fit.training.entity.ResponseEntity 
    * @Author: Izzat 
    * @Date: 2020/1/25  13:18
    */ 
    public ResponseEntity findPlanByCreator(@RequestBody RequestEntity request) {
        return dbRemote.findPlanByCreator(request);
    }

    @RequestMapping("deletePlanById")
    /**
    * @Description: 根据id删除计划
    * @Param: [request]
    * @return: izzat.fit.training.entity.ResponseEntity
    * @Author: Izzat
    * @Date: 2020/1/27  23:44
    */
    public ResponseEntity deletePlanById(@RequestBody RequestEntity request){
        return dbRemote.deletePlanById(request.getIds());
    }

    @RequestMapping("findActionSetByPlanId")
    /** 
    * @Description: 按计划id查找训练组 
    * @Param: [id]
    * @return: izzat.fit.training.entity.ResponseEntity 
    * @Author: Izzat 
    * @Date: 2020/1/16  16:21
    */ 
    public ResponseEntity findActionSetByPlanId(@RequestBody RequestEntity request) {
        return dbRemote.findActionSetByPlanId(request.getId());
    }

    @RequestMapping("addPlan")
    /** 
    * @Description: 增加一个训练计划
    * @Param: [request] 
    * @return: izzat.fit.training.entity.ResponseEntity 
    * @Author: Izzat 
    * @Date: 2020/3/16  22:07
    */ 
    public ResponseEntity addPlan(@RequestBody RequestEntity request) {
        return dbRemote.addPlan(request);
    }
}

